class Installation < ActiveRecord::Base
  
    
  validates :install_no,
    :uniqueness => true
  validates :order_id,
    :presence => true
  validates :installer_id,
    :creator_id,
    :installed_on,
    :install_no,
    :presence => true,
    :on => :update
  validates :should_be_payed_price,
    :payed_price, 
    :numericality => {
      :greater_than_or_equal_to => 0
    },
    :on => :update
  
  belongs_to :installer, :class_name => "Employee", :foreign_key => "installer_id"
  belongs_to :creator, :class_name => "Employee", :foreign_key => "creator_id"
  belongs_to :order
  has_many :install_items
  has_many :feeds, :dependent => :destroy
  
  before_create do |installation|
    installation.init_install_no
    installation.creator = Employee.current
  end
  
  def status
    ActiveSupport::StringInquirer.new(self[:status])
  end
  
  def init_install_no
    self.install_no ||= "IN#{DateTime.now.to_formatted_s(:number)}"
  end

end
